package com.aaa.gs.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import com.netflix.loadbalancer.RoundRobinRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * fileName:MyCustomRule
 * description:
 * author: Mr.Ge
 * createTime:2020/11/18 10:56
 * version:1.0.0
 */
@Configuration  //spring-config.cml application.xml <bean></bean>
public class MyCustomRule {
    /**
     * 初始化负载均衡策略
     * @return
     */
    @Bean //<bean id=iRul class='com.netflix.loadbalancer.IRule'></bean>
    public IRule iRule(){
        //七种负载均衡规则，选择随机算法
//        return new RandomRule();
        //选择轮询算法
//        return new RoundRobinRule();
        //调用自己写的随机算法
        return new MyRandomRule();
    }
}
